<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>票品推荐目录</title>
<%@include file="../header.jsp" %>
<script type="text/javascript" src="/js/jquery.ztree.all-3.5.js"></script>
<link rel="stylesheet" href="/css/zTreeStyle/zTreeStyle.css" type="text/css">
<style type="text/css">

#aa{ height:500px;}
#bb{margin-top:200px;}
</style>

<SCRIPT type="text/javascript">


	
	function zTreeOnMouseDown(event, treeId, treeNode) {
   // alert(treeNode ? treeNode.tId + ", " + treeNode.dictionaryId : "isRoot");
    
    refreshtree2(treeNode.dictionaryId);
    
	}
	
	///异步更新tree2
   function refreshtree2(dictionaryid)
   {
	   $.fn.zTree.init($("#treeDemo2"), ztreeSetting2, null);
		var treeObj = $.fn.zTree.getZTreeObj("treeDemo2");
		treeObj.setting.async.url="/adviced/getAdvicedCategory.htm?dicid="+dictionaryid;
		treeObj.setting.async.enable =true;
		treeObj.reAsyncChildNodes(null, "refresh"); 
   }
	
	////////////初始化树
	
		var ztreeSetting1 = {
				
				view: {
					selectedMulti: false
					//addDiyDom: addDiyDom
				}, 
				data:{
					
						key: {
							name: "name"
						
					},
					simpleData:{
						enable: true,
						idKey: "dictionaryId",
						pIdKey: "dicDictionaryId",
						rootPId: null
					}
				},
				callback: {
					onMouseDown: zTreeOnMouseDown
				}
			};
		var ztreeSetting2 = {
				async: {
					enable: false,
					url: "",
					autoParam: ["id", "name"]
				},
				view: {
					selectedMulti: false
					//addDiyDom: addDiyDom
				}, 
				data:{
					
						key: {
							name: "name2"
						}
					
				}
			};
		var ztreeSetting3 = {
				
				view: {
					selectedMulti: false
					//addDiyDom: addDiyDom
				}, 
				data:{
					key: {
						name: "name"
					},
					simpleData:{
						enable: true,
						idKey: "dictionaryId",
						pIdKey: "dicDictionaryId",
						rootPId: null
					}
				}
			};
		
		
		$(function(){

			var zNodes1 = ${trees1};
			$.fn.zTree.init($("#treeDemo1"), ztreeSetting1, zNodes1);
			
			//var zNodes2 = ${trees2};
			
			var zNodes3 = ${trees3};
			$.fn.zTree.init($("#treeDemo3"), ztreeSetting3, zNodes3);
		});
		

		


		////////////////////////////////////////////////////////////////// 操作
		function addadviced(id) {
            var treeObj1=$.fn.zTree.getZTreeObj("treeDemo1");
            
            var nodes1 = treeObj1.getSelectedNodes();
            if ( nodes1 == null || nodes1 == "")  
        	{
        	   alert("请在票品推荐目录选中一个节点"); //获取选中节点的值
        	   return;
        	}   
            
            var treeObj3=$.fn.zTree.getZTreeObj("treeDemo3");
            
            var nodes3 = treeObj3.getSelectedNodes();
            if ( nodes3 == null || nodes3 == "")  
        	{
            	alert("请在景区主题分类选中一个节点"); //获取选中节点的值
        	   return;
        	}                         
                    
            var dictionaryId = nodes1[0].dictionaryId;
            var dicdictionaryId = nodes3[0].dictionaryId;
            var treeObj2=$.fn.zTree.getZTreeObj("treeDemo2");
            var nodes = treeObj2.getNodes();
            var count = 0;
            $.each(nodes, function(i, n) {
            	if(n.dic_dictionary_id==dicdictionaryId) {
            		alert("请勿选择重复分类！！");
            		count++;
            		return false;
            	}
            })
            if(count>0)
            	return;
     
			$.ajax({
				url:"/adviced/addAdvicedCategory.htm?dictionaryid="+dictionaryId+"&dicdictionaryid="+dicdictionaryId,
				dataType:"json"
			}).done(function(data) {
				alert(data.msg);
				if(data.isSuccess) {
					refreshtree2(dictionaryId);
				}
			});
            
            
            
		}
		
		function deladviced(id) {
   			 var treeObj2=$.fn.zTree.getZTreeObj("treeDemo2");
   			 
             if (treeObj2 == null)  
         	{
         	   alert("请在票品推荐目录选中一个节点"); //获取选中节点的值
         	   return;
         	}               
   			 
            var nodes2 = treeObj2.getSelectedNodes();
            
            
            if ( nodes2 == null || nodes2 == "")  
        	{
        	   alert("请在被推荐的景区分类选中一个节点进行删除"); //获取选中节点的值
        	   return;
        	}          
        //    alert(JSON.stringify(nodes2));
            
            var dictionaryId = nodes2[0].dictionary_id;
            var id = nodes2[0].adviced_letf_category_id;
            var name1 = nodes2[0].name1;
            var name2 = nodes2[0].name2;

            
            if (typeof(id) == "undefined" || id == null)  
            	{
            	   alert("请在被推荐的景区分类选中一个节点进行删除"); //获取选中节点的值
            	   return;
            	}
            
            var r= confirm("将要删除"+id+","+name1+"-"+name2+",你确定么？"); //获取选中节点的值
            if (r==true)
            {
    			$.ajax({
    				url:"/adviced/delAdvicedCategory.htm?id="+id,
    				dataType:"json"
    			}).done(function(data) {
    				alert(data.msg);
    				if(data.isSuccess) {
    					refreshtree2(dictionaryId);
    				}
    			});
            }
            else
            {
             	return;
            }          
            

            
            
		}
		


	</SCRIPT>
	<style type="text/css">
		.ztree li span.demoIcon{padding:0 2px 0 10px;}
		.ztree li a.curSelectedNode{text-decoration:none; }
	</style>
</head>
<body>
<div class="ch-container">
	<div class="row">
        <div class="box col-md-3">
        <div class="box-inner">
            <div class="box-header well" data-original-title="">
                <h2><i class="glyphicon glyphicon-tasks"></i> 票品推荐目录：</h2>

                <div class="box-icon">
                    <a href="#" class="btn btn-setting btn-round btn-default"><i
                            class="glyphicon glyphicon-cog"></i></a>
                    <a href="#" class="btn btn-minimize btn-round btn-default"><i
                            class="glyphicon glyphicon-chevron-up"></i></a>
                    <a href="#" class="btn btn-close btn-round btn-default"><i
                            class="glyphicon glyphicon-remove"></i></a>
                </div>
            </div>
            <div class="box-content" id ="aa">
               <ul id="treeDemo1" class="ztree"></ul>
            </div>
        </div>
    </div>
    <!--/span-->
        <div class="box col-md-3">
        <div class="box-inner">
            <div class="box-header well" data-original-title="">
                <h2><i class="glyphicon glyphicon-tasks"></i> 被推荐的景区分类：</h2>

                <div class="box-icon">
                    <a href="#" class="btn btn-setting btn-round btn-default"><i
                            class="glyphicon glyphicon-cog"></i></a>
                    <a href="#" class="btn btn-minimize btn-round btn-default"><i
                            class="glyphicon glyphicon-chevron-up"></i></a>
                    <a href="#" class="btn btn-close btn-round btn-default"><i
                            class="glyphicon glyphicon-remove"></i></a>
                </div>
            </div>
            <div class="box-content" id = "aa">
                <ul id="treeDemo2" class="ztree"></ul>
            </div>
        </div>
    </div>
    <!--/span-->
       <div class="box col-md-2">
        <div > 
        <div id ="bb"> 
        <a href="javascript:;" class="btn btn-default" onclick="addadviced();">《《《添加</a><br>
        <br>
          <a href="javascript:;" class="btn btn-default" onclick="deladviced();">删除》》》</a>      
            </div>
             </div>
    </div>
    <!--/span-->
    
    <div class="box col-md-3">
        <div class="box-inner">
            <div class="box-header well" data-original-title="">
                <h2><i class="glyphicon glyphicon-tasks"></i> 景区主题分类：</h2>

                <div class="box-icon">
                    <a href="#" class="btn btn-setting btn-round btn-default"><i
                            class="glyphicon glyphicon-cog"></i></a>
                    <a href="#" class="btn btn-minimize btn-round btn-default"><i
                            class="glyphicon glyphicon-chevron-up"></i></a>
                    <a href="#" class="btn btn-close btn-round btn-default"><i
                            class="glyphicon glyphicon-remove"></i></a>
                </div>
            </div>
            <div class="box-content" id ="aa">

                <ul id="treeDemo3" class="ztree"></ul>
            </div>
        </div>
    </div>
    <!--/span-->

</div><!--/row-->
</div>
</body>
</html>